package com.jtzc.mcp.coze.infrastructure.exception;

import com.jtzc.mcp.coze.infrastructure.common.CommonConstants;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.LinkedList;

/**
 * 自定义异常
 */
@Data
@EqualsAndHashCode
public class GlobalException extends RuntimeException {

    private static final long serialVersionUID = 1L;

    //错误码
    private String code;

    //消息(可能包含{0}、{1}等数据,届时用params集合中对应顺序的值代替)
    private String msg;

    //异常字符串
    private String exception;

    //自定义返回参数(在msg中,如果遇到{0}、{1}等数据时,用params集合中对应顺序的值代替)
    private LinkedList<String> params;

    /**
     * 自定义构造器
     *
     * @param msg 消息
     */
    public GlobalException(String msg) {
        super(msg);
        this.code = CommonConstants.RETURN_CODE_500;
        this.msg = msg;
        this.exception = msg;
        this.params = new LinkedList<>();
    }

    /**
     * 自定义构造器(无自定义返回参数)
     *
     * @param code    错误码
     * @param msg 消息
     */
    public GlobalException(String code, String msg) {
        super(msg);
        this.code = code;
        this.msg = msg;
        this.exception = msg;
        this.params = new LinkedList<String>();
    }

    /**
     * 自定义构造器
     *
     * @param code    错误码
     * @param msg 消息
     * @param params  自定义返回参数
     */
    public GlobalException(String code, String msg, LinkedList<String> params) {
        super(msg);
        this.code = code;
        this.msg = msg;
        this.exception = msg;
        this.params = params;
    }

}
